package com.quanyan.travel.web;

import com.quanyan.api.APIResponse;
import com.quanyan.api.enums.ApiResponseEnum;
import com.quanyan.travel.api.req.ReqIndexTravelList;
import com.quanyan.travel.service.TravelIndexService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * Created with IntelliJ IDEA.
 * User: zyq
 * Date: 2016/5/27 0027
 * Time: 15:43
 */
@RestController @RequestMapping("/api/travel/index") public class IndexController {

    private static Logger log = LoggerFactory.getLogger(IndexController.class);

    @Autowired TravelIndexService indexService;

    @RequestMapping(value = "/outdoorIndex", method = RequestMethod.POST)
    public APIResponse<?> outdoorIndex() {
        return indexService.indexProperties();
    }

    @RequestMapping(value = "/productsList", method = RequestMethod.POST)
    public APIResponse<?> outdoorIndex(@RequestBody @Valid ReqIndexTravelList request,
        BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return APIResponse.returnFail(ApiResponseEnum.PARAMETER_INVALID);
        }
        return indexService.indexActivities(request);
    }
}
